package org.s3.project.controller;

import org.s3.project.common.R;
import org.s3.project.entity.Orders;
import org.s3.project.entity.Orderss;
import org.s3.project.entity.Shoshoping;
import org.s3.project.service.OrderssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author cfx
 * @version 1.0 1
 * @Description
 * @date 2025/2/9 9:32
 */
@RestController
@CrossOrigin(origins = "*") // 允许所有来源
public class OrderssController {
    @Autowired
    private OrderssService orderssService;

    //查询订单表中的基本信息条件为订单号
    @GetMapping("/selectorders1")
    public R selectOrders1(@RequestParam("number") String number ) {
        List<Orderss> Ordersslist = orderssService.selectOrders1(number);
        List<Shoshoping> shoshopings=new ArrayList<>();
        for(Orderss orders:Ordersslist){
            Shoshoping shoshoping = new Shoshoping(
                    orders.getAmount(),
                    orders.getOid(),
                    orders.getName(),
                    orders.getDish_id(),
                    orders.getDish_image(),
                    orders.getOrder_number(),
                    orders.getDish_price(),
                    orders.getDish_quantity()
            );
            shoshopings.add(shoshoping);
            System.out.println(shoshoping.getOid());
        }
            return new R().add("Ordersslist", Ordersslist).add("shoshopings", shoshopings);

    }

}
